<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
include_once("../config.inc.php");

$intLottoID = (int)$_data["LottoID"];
//if(!$intLottoID)$intLottoID = 1;
if(empty($intLottoID)){
	$intLottoID = (defined('__MemInitLottoID'))?__MemInitLottoID:1;
	if(empty($intLottoID))$intLottoID = 1;
}
$isOddsPlus = ($intLottoID == 4)?true:false;

$_LangPath = "memcreditdata";

if($isOddsPlus){
	include_once(__Member_Path."/logincheck.php");
	include_once(__Modules_Path."/SelectGambleType.lib.php");
	include_once(__Modules_Path."/Commission.lib.php");
}else{
	include_once(__Member_Path."/logincheck_nodb.php");
}
include_once(__Language_Path."/selectlanguage_member.php");
include_once(__Common_Path."/ExchangeRate.inc.php");
include_once(__Common_Path."/Lotto.inc.php");
include_once(__Modules_Path."/Lotto.lib.php");

$fp = @file(__Membertemplate_Path."/memcreditdata.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);
$fp = str_replace("{Account}", $_SESSION["Member_Info"] -> Account, $fp);
$fp = str_replace("{Name}", $_SESSION["Member_Info"] -> Name, $fp);
$fp = str_replace("{CreditLine}", $_SESSION["Member_Info"] -> CreditLine, $fp);
$fp = str_replace("{ShowMemERate}", $_ECRate[$_SESSION["Member_Info"] -> ERID]["Rate"], $fp);
$fp = str_replace("{ShowCurrency}", $_ECRate[$_SESSION["Member_Info"] -> ERID][$_intLang], $fp);
$fp = str_replace("{CommLine}", chr(64 + $_SESSION["Member_Info"] -> GambleType), $fp);

$arrLottoPower = getLottoUsePowerArray();
$strLOption = "";
foreach($_arrLotto as $intLID => $arrLo){
	if(!in_array($intLID, $arrLottoPower))continue;

	$strLOption .= "<option value='".$intLID."'".($intLID == $intLottoID?" selected":"").">".$arrLo["Lotto_".$_intLang]."</option>";
}
$fp = str_replace("{LottoOption}", $strLOption, $fp);
if(!$isOddsPlus){
	$fp = preg_replace("/<!--@ OddsPlus1 While Start @\/\/-->.+<!--@ OddsPlus1 While End @\/\/-->/s", "", $fp);
	$fp = preg_replace("/<!--@ OddsPlus2 While Start @\/\/-->.+<!--@ OddsPlus2 While End @\/\/-->/s", "", $fp);
	$fp = preg_replace("/<!--@ OddsPlus3 While Start @\/\/-->.+<!--@ OddsPlus3 While End @\/\/-->/s", "", $fp);
}else{
	//找出 Lotto 的賠率兌換，傳回陣列
	//$arrORate = getArrayLottoChRateData($intLottoID);
	//if($arrORate === false)ErrMsgOutputHTML("Error", "", 1);
	include_once(__Common_Path."/CommToOddsRate_".$intLottoID.".inc.php");
	$arrORate = $_arrChRate;

	//找出 使用者 的賠率兌換，傳回陣列
	$arrUserORate = getUserCommToOdds($_SESSION["Member_Info"] -> ID, $intLottoID, array());
	if($arrUserORate === false)ErrMsgOutputHTML("Error", "", 1);
}

preg_match("/<!--@ Lotto While Start @\/\/-->(.+)<!--@ Lotto While End @\/\/-->/s", $fp, $arrL);
preg_match("/<!--@ EventLimits While Start @\/\/-->(.+)<!--@ EventLimits While End @\/\/-->/s", $fp, $arrEL);
$strLTmp = $arrL[1];
$strELTmp = $arrEL[1];

$strCon = "";
$arrLo = $_arrLotto[$intLottoID];

$strEL = "";
$strL = "";
foreach($_arrBet_Type[$arrLo["LType"]] as $intBT => $strBT){

	if($isOddsPlus){
		$arrApointNumTip = $_arrGLineApointNumTip[$intLottoID][$intBT];
		if(!is_array($arrApointNumTip))$arrApointNumTip = array("");

		foreach($arrApointNumTip as $intAN => $strApointTip){
			$c = $strELTmp;
			$strOption = "";
			$flUserCO = (float)$arrUserORate[$intBT][$intAN][11];
			$flComm = 100 - $_SESSION["Member_Info"] -> arrCommission[$intLottoID][$intBT];
			$flORate = $arrORate[$intBT][$intAN][$_SESSION["Member_Info"] -> GambleType+10];
			$flGap = $flORate / 10;
			$flMaxOPlus = $flComm*$flORate;
			$flNewComm = $_SESSION["Member_Info"] -> arrCommission[$intLottoID][$intBT] + $flUserCO;
			$strColor = $flUserCO > 0 ? " color: #FF0000":"";

			if($flORate == 0 || $flComm == 0){
				$strOption .= "<option value='0'>0</option>";
			}else{
				for($i = 0; round($i*1000) <= round($flMaxOPlus*1000); $i += $flGap){
					$strOption .= "<option value='".($i / $flORate)."'".(round($flUserCO*$flORate*1000) == round($i*1000)?" selected":"").">".$i."</option>";
				}
			}
			$strOption = "<select name='OPlus[".$intBT."][".$intAN."]' style='width:55px' onchange='setNewComm(".$intBT.", ".$intAN.", this.value)'>".$strOption."</select>";
			$c = str_replace("{Show_OddsPlus}", $strOption, $c);
			$c = str_replace("{Show_NewLine}", "<a id='NComm_".$intBT."_".$intAN."' style='".$strColor."'>".$flNewComm."</a>", $c);

			$c = ($strApointTip == "")?str_replace("{BetType}", $strBT, $c):str_replace("{BetType}", $strBT." - ".$strApointTip, $c);
			$c = str_replace("{Show_Line}", "<a id='OComm_".$intBT."_".$intAN."'>".$_SESSION["Member_Info"] -> arrCommission[$intLottoID][$intBT]."</a>", $c);
			$c = str_replace("{EventLimit_1}", $_SESSION["Member_Info"] -> arrEventLimit[$intLottoID][$intBT], $c);
			$strEL .= str_replace("{BetLimit_1}", $_SESSION["Member_Info"] -> arrBetLimit[$intLottoID][$intBT], $c);
		}
	}else{
		$c = $strELTmp;
		$c = str_replace("{BetType}", $strBT, $c);
		$c = str_replace("{Show_Line}", "<a id='OComm_".$intBT."'>".$_SESSION["Member_Info"] -> arrCommission[$intLottoID][$intBT]."</a>", $c);
		$c = str_replace("{EventLimit_1}", $_SESSION["Member_Info"] -> arrEventLimit[$intLottoID][$intBT], $c);
		$strEL .= str_replace("{BetLimit_1}", $_SESSION["Member_Info"] -> arrBetLimit[$intLottoID][$intBT], $c);
	}
}
$strL = preg_replace("/<!--@ EventLimits While Start @\/\/-->.+<!--@ EventLimits While End @\/\/-->/s", $strEL, $strLTmp);
$strCon .= str_replace("{LottoName}", $arrLo["Lotto_".$_intLang], $strL);

$fp = preg_replace("/<!--@ Lotto While Start @\/\/-->.+<!--@ Lotto While End @\/\/-->/s", $strCon, $fp);

while(list($k, $v) = each($_strMemCreditData)){
	$fp = str_replace("{".$k."}", $v, $fp);
}

//輸出
WebOutputHTML($fp, 1);
?>